#include <cstdio>
#include <queue>
#define maxn 5005
#define INF 2147483647
using namespace std;

using pii = pair<int, int>;
vector<pii> G[maxn];
int dis[maxn];

int main()
{
	int n, m;
	scanf("%d%d", &n, &m);
	while(m--)
	{
		int u, v, w;
		scanf("%d%d%d", &u, &v, &w);
		G[--u].emplace_back(--v, w);
		G[v].emplace_back(u, w);
	}
	for(int i=1; i<n; i++)
		dis[i] = INF;
	priority_queue<pii, vector<pii>, greater<pii>> q;
	q.emplace(0, 0);
	int ans = 0, left = n;
	while(!q.empty() && left > 0)
	{
		auto [d, v] = q.top(); q.pop();
		if(d != dis[v]) continue;
		dis[v] = -INF, left --, ans += d;
		for(auto [u, w]: G[v])
			if(w < dis[u])
				q.emplace(dis[u] = w, u);
	}
	if(left) puts("orz");
	else printf("%d\n", ans);
	return 0;
}
